﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Sirenix.OdinInspector;
namespace Data
{
    [Serializable]
    [TypeConverter(typeof(Vector3Converter))]
    public class Vector3
    {
        private float x;
        private float y;
        private float z;
        public float this[int index]
        {
            get
            {
                if (index == 0)
                {
                    return x;
                }
                else if (index == 1)
                {
                    return y;
                }
                else if (index == 2)
                {
                    return z;
                }
                throw new ArgumentException();
            }
            set
            {
                if (index == 0)
                {
                    x = value;
                }
                else if (index == 1)
                {
                    y = value;
                }
                else if (index == 2)
                {
                    z = value;
                }
                throw new ArgumentException();
            }
        }

        [HorizontalGroup(LabelWidth = 20)]
        [DefaultValue(0.0f)]
        public float X { get { return x; } set { x = value; } }
        [HorizontalGroup(LabelWidth = 20)]
        [DefaultValue(0.0f)]
        public float Y { get { return y; } set { y = value; } }
        [HorizontalGroup(LabelWidth = 20)]
        [DefaultValue(0.0f)]
        public float Z { get { return z; } set { z = value; } }

        public Vector3(float mX, float mY, float mZ)
        {
            x = mX;
            y = mY;
            z = mZ;
        }

        public Vector3()
        {
            x = y = z = 0;
        }

        public override string  ToString()
        {  
            return  X + " " + Y + " " + Z;  
        }
        public float magnitude
        {
            get { return MathUtility.Magnitude(this); }
        }
        public static Vector3 zero
        {
            get { return new Vector3(0, 0, 0); }
        }
        public static Vector3 right
        {
            get { return new Vector3(1, 0, 0); }
        }

        public static Vector3 back { get { return new Vector3(0, 0, -1); } }

        public static Vector3 down { get {return new Vector3(0, -1, 0); } }

        public static Vector3 forward { get { return new Vector3(0, 0, 1); } }


        public static Vector3 left { get {return new Vector3(-1, 0, 0); } }

        public static Vector3 one { get {return new Vector3(1, 1, 1); } }
        public Vector3 normalized
        {
            get
            {
                return new Vector3(X/magnitude,Y/magnitude,Z/magnitude);
            }
        }
        public static Vector3 up { get { return new Vector3(0, 1, 0); } }
        public static Vector3 Zero
        {
            get { return new Vector3(0,0,0);}
        }
    }
}
